Skip to content

gh-161934: Make print() use a single write() call - #161936

Open
methane wants to merge 4 commits into
python:mainfrom
methane:codex/textio-print2
Open

methane wants to merge 4 commits into
python:mainfrom
methane:codex/textio-print2

Conversation

@methane

@methane methane commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35886605 | 📁 Comparing f0fa0a2 against main (d8d560b)

  🔍 Preview build  

4 files changed
± builtins/functions.html
± c-api/dict.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@methane
methane force-pushed the codex/textio-print2 branch from fd7f7ec to d5def80 Compare November 14, 2026 05:48

@cmaloney cmaloney left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to microbenchmark performance numbers, two high level comments:

  1. This pretty comprehensively rewrites write in TextIOWrapper while adding the new write_list. That is intricate and I think should be a PR of its own for reviewability. There's a lot of buffering edgecases and bugfix comments in rewritten code.

  2. If someone prints 40 million ints comma separated or 16 x 1GB strings this is going to spend a long time building up the list while not printing (and if it OOMs likely never printing). I think there needs to be a pending_bytes_count > chunk_size just like TextIOWrapper's buffering had. Happy for that to be a modern constant default of multi-MB though. Care about the edge cases (ex. printing a list of 16 x 1GB strings) having reasonable behavior.

    With unintended recursion while developing things tend to run into long accidental strings and often I print() debug to figure out "what is happening".

@methane

methane commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Looking forward to microbenchmark performance numbers,

https://gist.github.com/methane/fb1d38b82ae1934eb19e10dcfef72a08

  1. This pretty comprehensively rewrites write in TextIOWrapper while adding the new write_list. That is intricate and I think should be a PR of its own for reviewability. There's a lot of buffering edgecases and bugfix comments in rewritten code.

Most of the changes to textio.c are due to splitting up write(). I've created a separate PR for that part first.

#161991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review topic-IO type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants